<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <div id="app">
    <home></home>
  </div>
  <script src="./vue.js"></script>
  <script>
    const bus = new Vue();
    const Child1 = {
      template:`
        <div>
          这是大儿子
          <button @click="a">按钮</button>
        </div>
      `,
      data(){
        return {
          msg:"我是你哥的数据"
        }
      },
      methods: {
        a(){
          bus.$emit('aaa', this.msg)
        }
      }
    }
    const Child2 = {
      template:`
        <div>
          这是2儿子
          {{msg}}
        </div>
      `,
      data(){
        return {
          msg:''
        }
      },
      mounted(){
         bus.$on("aaa",(msg)=>{
          this.msg = msg;
          alert('收到了兄弟')
        }) 
        // const _this = this;
       /*  bus.$on("aaa",function(msg){
          console.log(this)
         this.msg = msg;
        }.bind(this)) */
      }
    }
    // 定义全局组件
    const Home = {
      template:`
        <div>
          <h3>这是父组件</h3>
          <child1></child1>
          <hr/>
          <child2></child2>
        </div>
        
      `,
      data(){
        return {
          msg:'我是home组件的数据'
        }
      },
      components:{
        Child1,
        Child2
      }
    }
    Vue.component("Home", Home)
    const vm = new Vue({
      el:"#app"
    })

    function fn(){
      console.log(this)
    }
    // fn.call(2);
    const fn2 = fn.bind(2);

    btn.onclick = fn
  </script>
</body>
</html>
